﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DataModel;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace MetaDesigner
{    
    /// <summary>
    /// Interaction logic for TermLabelAttributeManager.xaml
    /// </summary>
    public partial class TermSetLabelAttributeManager : Window
    {
        TermSet ts;

        /// <summary>
        /// Initializes a new instance of the <see cref="TermSetLabelAttributeManager"/> class.
        /// </summary>
        /// <param name="t">The t.</param>
        public TermSetLabelAttributeManager(TermSet t)
        {
            InitializeComponent();
            this.ts = t;

            UpdateSharedPropertiesDataGrid();
        }

        /// <summary>
        /// Updates the shared properties data grid.
        /// </summary>
        public void UpdateSharedPropertiesDataGrid()
        {
            SharedPropertiesDataGrid.ItemsSource = ts.SharedCustomProperties;
        }

        /// <summary>
        /// Handles the Closed event of the Window control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void Window_Closed(object sender, EventArgs e)
        {
            SharedPropertiesDataGrid.ItemsSource = null;
        }

        /// <summary>
        /// Handles the Closing event of the Window control. Checks for duplicate keys.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="CancelEventArgs"/> instance containing the event data.</param>
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            if (ts.SharedCustomProperties.HasDupes)
            {
                e.Cancel = true;
                MessageBox.Show("One or more keys in the properties are duplicated. Please ensure there are no duplicated Keys and try again.");
            }
        }
    }
}
